<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head th:replace="fregments :: head(~{::title})">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>链接详情</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="../static/lib/bootstrap-3.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="../static/css/my.css">
    <!-- 动画 -->
    <link rel="stylesheet" href="../static/css/animate.css">
</head>

<body>
<nav th:replace="fregments :: menu(0)" class="navbar navbar-default navbar-fixed-top m-padding">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">
                <img alt="Brand" src="../static/favicon.ico" style="width: 24px;">
            </a>
            <p class="navbar-text navbar-default"><a href="#" class="navbar-link m-a-none"><b>挚夕导航</b></a></p>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#"><span class="glyphicon glyphicon-home">&nbsp;</span>首页</a></li>
                <li><a href="#"><span class="glyphicon glyphicon-pencil">&nbsp;</span>学习</a></li>
                <li role="presentation" class="disabled"><a href="#"><span
                        class="glyphicon glyphicon-bookmark">&nbsp;</span>个人书签</a></li>
            </ul>

            <ul class="nav navbar-nav navbar-right">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">
                        <img class="m-avatar img-circle" src="../static/images/me.jpg">
                        挚夕
                        <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-left">
                        <li><a href="#"><span class="glyphicon glyphicon-th">&nbsp;</span>个人主页</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#"><span class="glyphicon glyphicon-log-out">&nbsp;</span>登出</a></li>
                    </ul>
                </li>
            </ul>

            <form class="navbar-form navbar-right">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="搜索" style="width: 300px;">
                </div>
                <button type="submit" class="btn btn-default">
                    <a class="glyphicon glyphicon-search m-none"></a>
                </button>
            </form>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<th:block th:replace="fregments :: modal"></th:block>

<div id="way-point" class="animated fadeIn">
    <div class="m-container" id="myContainer">
        <!-- 内容开始 -->
        <div name="content" class="row">
            <div class="col-xs-12 col-sm-9 col-md-9 left-container">
                <!-- 面板开始 -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        链接详情
                    </div>
                    <div class="panel-body row">
                        <!-- 左边div开始-->
                        <div class="left-container col-xs-12 col-sm-12 col-md-12">
                            <!-- 左边图标、简述开始-->
                            <div class="left-top">
                                <div class="col-xs-12 col-sm-5 col-md-4 panel panel-default left-image">
                                    <div class="panel-body">
                                        <div class="col-xs-12 col-sm-12 col-md-12">
                                            <img src="https://img.ishuqian.com/wp-content/uploads/2022/12/57678-www.bilibili.com.png"
                                                 th:src="${link.icon}" style="width: 100px">
                                        </div>
                                    </div>
                                </div>
                                <div class="panel-body col-xs-12 col-sm-7 col-md-8">
                                    <h4 class="m-title" th:text="${link.title}">
                                        bilibili
                                    </h4>
                                    <p class="m-text" th:text="${link.brief}">
                                        哔哩哔哩
                                    </p>
                                    <div>
                                        <!-- 标签-->
                                        <span th:each="tag : ${tags}" class="m-tag" th:classappend="${tag.labelClass}"
                                              th:data-id="${tag.id}"
                                              th:text="${tag.name}">ACG</span>
                                    </div>
                                    <br>
                                    <div id="starContainer">
                                        <th:block th:fragment="star">
                                            <span style="font-size: 16px" data-toggle="tooltip" data-placement="left"
                                                  title="浏览" class="glyphicon glyphicon-eye-open"
                                                  th:text="${link.viewCnt}">12</span>

                                            <span th:data-id="${link.id}" id="star" style="font-size: 16px"
                                                  data-toggle="tooltip" data-placement="right" title="收藏"
                                                  class="m-pointer glyphicon "
                                                  th:classappend="${star} ? 'glyphicon-star' : 'glyphicon-star-empty'"
                                                  th:text="${link.star}">1</span>
                                        </th:block>
                                    </div>
                                    <div>
                                        <a type="button" class="btn btn-primary" id="btn-go" role="button"
                                           target="_blank" th:href="${link.url}">链接直达
                                        </a>
                                        <a tabindex="0" id="btn-phone" class="btn btn-success" role="button"
                                           data-toggle="popover" data-trigger="focus" title="扫码查看"
                                           data-placement="bottom">手机查看</a>
                                    </div>
                                </div>

                            </div><!-- 左边图标、简述结束-->
                            <!-- 详情-->
                            <div class="col-xs-12 col-sm-12 col-md-12">
                                <p th:text="${link.detail}">
                                    哔哩哔哩(bilibili.com)是国内知名的视频弹幕网站，这里有及时的动漫新番，活跃的ACG氛围，有创意的Up
                                    主。大家可以在这里找到许多欢乐。
                                </p>
                            </div>
                            <!-- 相关链接-->
                            <div class="col-xs-12 col-sm-12 col-md-12">
                                <h4>
                                    <span class="glyphicon glyphicon-tasks"></span>&nbsp;相关链接
                                </h4>
                                <!-- row start -->
                                <div class="row">
                                    <div class="col-xs-12 col-sm-6 col-md-4" th:each="link : ${relatedLinks}">
                                        <div class="m-card row animated lightSpeedIn">
                                            <a class="m-padded-left-sm m-padded-none col-xs-11 col-sm-11 col-md-11 m-a-none"
                                               th:href="@{/link/{id}(id=${link.id})}">
                                                <!--                                    <div class="m-inline">-->
                                                <div class="m-margin-top-sm m-padded-none col-xs-2 col-sm-2 col-md-2">
                                                    <img class="m-png img-circle"
                                                         th:src="${link.icon}">
                                                </div>
                                                <div class="m-padded-none m-padded-top-sm col-xs-10 col-sm-10 col-md-10">
                                                    <div>
                                                        <strong th:text="${link.title}">哔哩哔哩</strong>
                                                    </div>
                                                    <!--                                            #strings.substring(link.brief, 0, #strings.length(link.brief) > 8 ? 8 : #strings.length(link.brief)) + '...'-->
                                                    <div class="text-muted m-brief-control m-inline"
                                                         th:text="${link.brief}">哔哩哔哩干杯
                                                    </div>
                                                </div>
                                                <!--                                    </div>-->
                                            </a>
                                            <a class="m-margin-top-big m-padded-none col-xs-1 col-sm-1 col-md-1 m-a-none m-padded-top"
                                               th:href="${link.url}" target="_blank"
                                               data-toggle="tooltip" data-placement="bottom" title="直达">
                                                <span class="glyphicon glyphicon-chevron-right">&nbsp;</span>
                                            </a>
                                        </div>
                                    </div>

                                </div> <!-- row end -->

                            </div>
                            <br><br>
                            <br><br>
                        </div><!-- 左边div结束-->
                    </div>
                </div><!-- 面板结束 -->
            </div>
            <div class="col-xs-12 col-sm-3 col-md-3 right-container">
                <div class="right-container col-xs-12 col-sm-12 col-md-12">
                    <div class="panel panel-default ">
                        <div class="panel-heading">
                            <span class="glyphicon glyphicon-tags"></span> 热门标签
                        </div>
                        <div class="panel-body">
                            <span th:each="tag : ${hotTags}" class="m-tag" th:data-id="${tag.id}"
                                  th:classappend="${tag.labelClass}" th:text="${tag.name}">ACG</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--二维码-->
<div id="qrcode" style="display: none">

</div>
<br><br><br><br><br><br><br><br><br>
<footer th:replace="fregments :: footer">
    <div>
        <div class="row">
            <div class="col-sm-4 col-md-4">
                <h3>挚夕导航</h3>
                <p>
                    挚夕导航最初源于本人想要做一个管理书签的系统。<br>
                    后来借鉴了一些导航网站，决定做一个网站导航。<br>
                    前端使用BootStrap。
                </p>
            </div>
            <div class="col-sm-8 col-md-8">
                占位
            </div>
        </div>
    </div>

    <div style="text-align: center;">
        Copyright 2023-now 挚夕导航 Designed by 挚夕
    </div>
</footer>

<!--/*/<th:block th:replace="fregments::script">/*/-->
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="../static/lib/jquery-1.12.4/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="../static/lib/bootstrap-3.4.1/js/bootstrap.min.js"></script>
<!--  bootstrap-dropdown-hover -->
<script src="../static/lib/bootstrap-dropdown-hover.js"></script>
<!--  二维码-->
<script src="../static/lib/qrcode/qrcode.min.js"></script>
<script>
    $(function () {
        //bootstrap-dropdown-hover
        $('.navbar [data-toggle="dropdown"]').bootstrapDropdownHover({
            // see next for specifications
        });
        setTimeout(() => {
            $(".m-card").removeClass("lightSpeedIn");
        }, 3000);
        //特效
        $("li").hover(function () {
            $(this).toggleClass("m-up");
        })
    });
</script>
<!--/*/</th:block>/*/-->

<script>
    function reloadScript() {
        setTimeout(() => {
            $(".m-card").removeClass("lightSpeedIn");
        }, 2000);
    }

    //加载收藏页面片段
    function reloadStarContainer() {
        console.log('reloadStarContainer')
        var linkId = $('#star').data('id');
        console.log(linkId)
        $.ajax({
            type: 'get',
            data: {
                linkId: linkId
            },
            headers: {
                authorization: localStorage.getItem('token')
            },
            url: '[[@{/link/starContainer}]]',
            success: function (data) {
                console.log(data);
                $("#starContainer").html(data);
            }
        })
    }

    $(function () {
        reloadStarContainer();
        //卡片特效
        $("#myContainer").on('mouseenter', '.m-card', function () {
            $(this).toggleClass("m-grow")
        });
        $("#myContainer").on('mouseleave', '.m-card', function () {
            $(this).toggleClass("m-grow")
        });

        $(".m-tag").click(function () {
            var id = $(this).data('id');
            window.location.href = "[[@{/tag/}]]" + id;
        });

        var url = "[[${link.url}]]";
        //生成网址二维码
        var qrcode = new QRCode("qrcode", {
            text: url,
            width: 100,
            height: 100,
            colorDark: "#000000",
            colorLight: "#ffffff",
            correctLevel: QRCode.CorrectLevel.H
        });
        $('#btn-phone').popover({
            trigger: 'hover',
            html: 'true',
            content: function () {
                return $("#qrcode").html();
            },
            animation: false,
            placement: 'bottom'
        });
        //收藏链接
        $("#myContainer").on('click', '#star', function () {
            var token = localStorage.getItem('token');
            if (token == null) {
                toastr.info('请先登录', '提示');
                return;
            }
            var bool = $(this).hasClass('glyphicon-star')
            $.ajax({
                type: 'post',
                data: {
                    linkId: $(this).data('id'),
                    star: !bool
                },
                headers: {
                    authorization: localStorage.getItem('token')
                },
                url: '[[@{/link/star}]]',
                success: function (response) {
                    if (response.status == 'success') {
                        if (bool) {
                            $("#star").removeClass('glyphicon-star');
                            $("#star").addClass('glyphicon-star-empty');
                            toastr.success('取消收藏', '提示');
                        } else {
                            $("#star").removeClass('glyphicon-star-empty');
                            $("#star").addClass('glyphicon-star');
                            toastr.success('收藏成功', '提示');
                        }
                        reloadStarContainer();
                    } else {
                        toastr.error('操作失败', '提示');
                    }
                },
                error: function (response) {
                    console.log('收藏失败:');
                    console.log(response.data);
                    toastr.error('操作失败', '提示');
                }
            })
        })
        // $("#star").click()
    });
</script>
</body>

</html>